<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\common\model\card\Type;
use app\common\model\Machine;
use app\common\model\Merchant;
use app\common\model\Merchantuser;
use app\common\model\Mycard;
use app\common\model\Mycardlog;
use app\common\model\Regionserviceuser;
use Exception;
use fast\Random;
use think\Db;

/**
 * 飞狗店铺管理
 */
class Flyshop extends Api
{
    protected $noNeedLogin = [];
    protected $noNeedRight = ['*'];
    /**
     * 获取门店列表
     * */
    public function getFlyList(){
        $page = !$this->request->param('page') ? 1 : $this->request->param('page');//页
        $list=Merchant::field("id,name,fly_price")
            ->where(["is_trila"=>'1'])
            ->order("createtime","desc")
            ->paginate(10, '', ['page' => $page, 'list_rows' => 10])
            ->each(function ($v){
                $highest_price=Type::field("price")->find(30);
                $v["highest_price"]=$highest_price["price"];
            });
        $this->success("成功",$list);
    }
    /**
     * 设置机器结算价格
     * */
    public function setFlyPrice(){
        $data=[
            ['id', 'require', '店铺id不能为空'],
            ['fly_price', 'require', '价格不能为空'],
        ];
        $validate = new \think\Validate($data);
        if (!$validate->check(input())) {
            $this->error('提交失败：' . $validate->getError());
        }
        $params = $this->request->param();
        $merchant=Merchant::get($params["id"]);
        if(empty($merchant)) $this->error("店铺不存在");
        $merchant->allowField(true)->save($params);
        $this->success("成功");
    }

    
}
